import { apiAll } from './index'
import { getPageSize } from '@/utils/currency'
import type { AssetMetadata } from '@/types/AssetMetadata'
import { assetProvider, namespaceProvider } from '@/plugins/account.ts'
import {
    AssetMetadataJson,
    SearchAssetConditionJson,
    SearchNamespaceConditionJson
} from '@yeying-community/yeying-client-ts'

// 创建命名空间
export const namespaceCreate = (name: string, description?: string) =>
    apiAll(() => namespaceProvider.create(name, description ?? ''))

// 更新资产的信息
export const assetUpdate = (asset: AssetMetadata) =>
    apiAll(() => assetProvider.update(asset as unknown as AssetMetadataJson))

// 删除资产，根据命名空间 ID 和哈希值删除资产
export const assetDelete = (namespaceId: string, hash: string) => apiAll(() => assetProvider.delete(namespaceId, hash))

// 搜索命名空间
export const namespaceSearch = (condition?: SearchNamespaceConditionJson) =>
    apiAll(() => namespaceProvider.search(1, getPageSize(), condition))

// 获得命名空间
export const namespaceGet = (uid: string) => apiAll(() => namespaceProvider.detail(uid))

// 搜索资产，根据条件和分页参数查询资产列表
export const assetSearch = (condition?: SearchAssetConditionJson) =>
    apiAll(() => assetProvider.search(1, getPageSize(), condition))
